//
//  LXPermissionSiri.swift
//  LXPermissionAuth
//
//  Created by yoctech on 2021/8/18.
//

import UIKit
import Intents

@objc class LXPermissionSiri: NSObject, LXPermissionProtocol {
    @objc public static func auth(autoRequestIfNot: Bool, clouser: @escaping LXAuthClouser) {
        let aStatus = INPreferences.siriAuthorizationStatus()
        switch aStatus {
        case .notDetermined:
            if !autoRequestIfNot {
                clouser(false,  .other)
                return
            }
            DispatchQueue.main.async {
                INPreferences.requestSiriAuthorization { (status) in
                    if status == .authorized{
                        clouser(true,  .authorized)
                    }else{
                        clouser(false,  .other)
                    }
                }
            }
        case .restricted:
            clouser(false,  .restricted)
        case .denied:
            clouser(false,  .denied)
        case .authorized:
            clouser(true,  .authorized)
        @unknown default:
            clouser(false,  .other)
        }
    }
    

}
